import {getCurrentUser} from '@/libs/util'
import {hasOneOf, typeOf} from '@/libs/tools'

/**
 * 验证权限
 * @param targetArr
 * @returns {*}
 */
export const hasResourceAccess = (targetArr) => {
    // 当传入的权限数组为空或不合法，则认为不需要权限判断
    if (!targetArr || typeOf(targetArr) !== "array" || targetArr.length === 0) {
        return true
    }
    let userStr = getCurrentUser();
    let user = JSON.parse(userStr)
    if (user && user.permissionList) {
        return hasOneOf(targetArr, user.permissionList);
    } else {
        return false
    }
};
